package com.yanqu.road.server.manger.activity.musicroomrank;

import com.yanqu.road.pb.activity.MusicRoomRankProto;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.musicroom.MusicRoomRankActivityModule;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.utils.executor.GeneralTask;

import java.util.List;
import java.util.Map;

public class MusicRoomRankActivityTask extends GeneralTask {
    private int round;
    private int theme;
    private Map<Long, List<MusicRoomRankProto.MusicRoomRankShowTemp>> userResultMap;

    public MusicRoomRankActivityTask(int round, int theme, Map<Long, List<MusicRoomRankProto.MusicRoomRankShowTemp>> userResultMap) {
        this.round = round;
        this.theme = theme;
        this.userResultMap = userResultMap;
    }

    @Override
    public void doRun() {
        try {
            for (Map.Entry<Long, List<MusicRoomRankProto.MusicRoomRankShowTemp>> entry : userResultMap.entrySet()) {
                Long userId = entry.getKey();

                GamePlayer onlinePlayer = GamePlayerMgr.getOnlinePlayer(userId);
                if (onlinePlayer != null) {
                    onlinePlayer.getModule(MusicRoomRankActivityModule.class).showResultCrossBack(entry.getValue(), round, theme);
                } else {
                    onlinePlayer = GamePlayerMgr.getPlayer(userId);
                    if (onlinePlayer != null) {
                        onlinePlayer.getModule(MusicRoomRankActivityModule.class).showResultCrossBack(entry.getValue(), round, theme);
                    } else {
                        getLOGGER().error("MusicRoomRankActivityTask doRun error, userId:{}", userId);
                    }
                }
            }
        } catch (Exception e) {
            getLOGGER().error("MusicRoomRankActivityTask doRun error", e);
        }

    }
}
